<%@page import="helpers.StringHelper"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%@page import="entities.Article"%>
<%@page import="entities.Application"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
String form = (String) request.getAttribute("form");
Application app = (Application) request.getAttribute("app");
Article article = (Article) request.getAttribute("article");
List<Category> categories = (List<Category>) request.getAttribute("categories");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<script type="text/javascript" src="/admin/js/plugins/wysiwyg/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="/admin/js/plugins/wysiwyg/wysiwyg.image.js"></script>
<script type="text/javascript" src="/admin/js/plugins/wysiwyg/wysiwyg.link.js"></script>
<script type="text/javascript" src="/admin/js/plugins/wysiwyg/wysiwyg.table.js"></script>
<script type="text/javascript" src="/admin/js/article_form.js"></script>

		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/article/list/<%=app.getId()%>">Article Manager</a></li>
                	<li><a href="/admin/article/search/<%=app.getId()%>">Search Article</a></li>
                	<li class="current"><a><%=form.equalsIgnoreCase("edit") ? "Update Article" : "Add New Article" %></a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<jsp:include page="/admin/elements/message_box.jsp" />
                    <div class="contenttitle">
                    	<h2 class="form"><span>Information</span></h2>
                    </div><!--contenttitle-->
            
                    <form method="post" action="#" class="stdform stdform2" id="edit_article_form">
                    	<p>
                        	<label>Author Name</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="authorName" id="a_authorName" value="<%=article.getAuthorName() != null ? article.getAuthorName() : "" %>">
                            	<% if (check.get("authorName") != null) { %>
									<label for="a_authorName" generated="true" class="error"><%=check.get("authorName") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Author Email</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="email" id="a_email" value="<%=article.getEmail() != null ? article.getEmail() : "" %>">
                            	<% if (check.get("email") != null) { %>
									<label for="a_email" generated="true" class="error"><%=check.get("email") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Title</label>
                            <span class="field">
                            	<input type="text" class="longinput" name="title" id="a_title" value="<%=article.getTitle() != null ? article.getTitle() : "" %>">
                            	<% if (check.get("title") != null) { %>
									<label for="a_title" generated="true" class="error"><%=check.get("title") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Category</label>
                            <span class="field">
                            	<select name="category" id="a_category">
                            		<% for (int i = 0; i < categories.size(); i++) { %>
                            		<option value="<%=categories.get(i).getId()%>"><%=categories.get(i).getName()%></option>
                            		<% } %>
                            	</select>
                            	<% if (check.get("category") != null) { %>
									<label for="a_category" generated="true" class="error"><%=check.get("category") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Content</label>
                            <span class="field">
                            	<textarea id="a_content" class="longinput" name="content"  rows="5" cols="80"><%=article.getContent() != null ? article.getContent() : "" %></textarea>
                            	<% if (check.get("content") != null) { %>
									<label for="a_content" generated="true" class="error"><%=check.get("content") %></label>
								<% } %>
                            </span> 
                        </p>
                        
                        <p>
                        	<label>Keyword</label>
                            <span class="field">
                            	<input type="text" class="longinput" name="keywords" id="a_keywords" value="<%=StringHelper.listToString(article.getKeywords(), ", ")%>">
                            	<% if (check.get("keywords") != null) { %>
									<label for="a_keywords" generated="true" class="error"><%=check.get("keywords") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Author Website</label>
                            <span class="field">
                            	<input type="text" class="longinput" name="website" id="a_website" value="<%=article.getWebsite()%>">
                            	<% if (check.get("website") != null) { %>
									<label for="a_website" generated="true" class="error"><%=check.get("website") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="stdformbutton">
                        	<button class="submit radius2">Submit</button>
                            <input type="reset" value="Reset" class="reset radius2">
                        </p>
                        
                    </form>
                    
                    <br clear="all">
                    
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp" />
            
        </div>

<jsp:include page="/admin/layouts/footer.jsp" />